﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OneShoppingDAL;
using OneShoppingBLL;
using OneShoppingUtility;
using OneShoppingModel;

public partial class Backstage_Pages_sysmng_personalPsw : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (role.RoleId > 2 || role.RoleId < 1)
        {
            Response.Redirect("../../login.html");
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        SystemUser user = (SystemUser)Session["user"];

        string textold=oldpsw.Text.Trim();
        string textnew=newpsw.Text.Trim();
        string textnew2=newpsw2.Text.Trim();
        if(textold=="")
        {
            msg_oldpsw.InnerText = "请输入旧密码";
            msg_oldpsw.Visible = true;
            return;
        }
        if(textnew=="")
        {
            msg_newpsw.InnerText = "请输入旧密码";
            msg_newpsw.Visible = true;
            return;
        }
        if(textnew2=="")
        {
            msg_newpsw2.InnerText = "请再次输入密码";
            msg_newpsw2.Visible = true;
            return;
        }
        if (textold != user.LoginPwd)
        {
            msg_oldpsw.InnerText = "旧密码错误";
            msg_oldpsw.Visible = true;
            return;
        }
        if(textnew!=textnew2)
        {
            msg_newpsw2.InnerText = "两次密码不相同";
            msg_newpsw2.Visible = true;
            return;
        }
        user.LoginPwd = textnew;

        bool result= SystemUserBLL.GetInstance().Update(user);
        if(result)
        {
            UtilityMessageBox.Show(this, "更改密码成功");
        }
        else
        {
            UtilityMessageBox.Show(this, "更改密码失败");
        }
    }
}